{% extends "master_page.html" %}

{% block title %}Edit <%= get_human_db_ref(@table.TableName) %>{% endblock %}
{% block content %}
<style>
label { float: left; }
label.error { float: none; color: red; padding-left: .5em; vertical-align: top; }
</style>
<script type="text/javascript" src="/js/jquery.validate.js"></script>
<script type="text/javascript">
//========================================================================================
function isFormOkay()
{   
	var result
	result = validator.form();
    return result;
	//return true;
}
//========================================================================================
function saveRecord(bitClose)
{
    if(isFormOkay())
    {
        var f = document.forms["main_form"]
        f.close_record.value = bitClose ? "1" : "0"
        f.submit();
    }
}
//========================================================================================
function deleteRecord()
{
    var f 
	f = document.forms["main_form"];
	if(f.key.value.length > 0){
		if(confirm("Are you sure?"))
		{
			window.location = "delete?id=" + f.key.value
		}
	}else{
		alert("New record can not be deleted.");
	}
}
//========================================================================================
function closeRecord()
{
    window.location='list'
}
//========================================================================================
var validator
$(document).ready(function(){
	validator = $("#main_form").validate();
});
</script>
</head>
<form name='main_form' id="main_form"  action='edit_save' method='POST'>
    <input type="hidden" name="key" value="{{record.key}}">
    <input type="hidden" name="close_record" value="0">

	<div class="divEditFormNavButtons">	
    <a href="edit?action=new"  class="aNavLink"  >Add</a>
    <a href="javascript:saveRecord(false);"  class="aNavLink">Save</a>
    <a href="javascript:saveRecord(true);"  class="aNavLink">Save & Close</a>
    <a href="javascript:deleteRecord();"  class="aNavLink">Delete</a>
    <a href="javascript:closeRecord()"   class="aNavLink">Close</a>
	</div>

<% for col in @table.Columns %>
	<label for="<%= col.ColumnName %>"><%= get_human_db_ref(col.ColumnName) %></label>:<br>	
	<input type='text' name='<%= col.ColumnName %>' 
	    id='<%= col.ColumnName %>' 
		style="width:300px;"
		value='{{record.<%= col.ColumnName %>}}'
		class="<%= col.AllowDBNull==false ? "required " : "" %><%= @jquery_validation_class_from_dot_net_type[col.DataType.to_s()]%>"
	><br>	
<% end %>
</form>
{% endblock %}